package com.fy.fyzf.dialog;

import android.app.Activity;
import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.PopupWindow;

import com.example.zhouwei.library.CustomPopWindow;
import com.fy.fyzf.R;

import ui.activity.IssueDemandActivity;

public class AreaPopwindow {
    private Context mContext;
    private View view;
    private View popView;
    private CustomPopWindow customPopWindow;

    public AreaPopwindow(Context context) {
        mContext = context;
    }

    public AreaPopwindow setView(View v) {
        view = v;
        popView = LayoutInflater.from(mContext).inflate(R.layout.popwindow_area, null, false);
        return this;
    }
    public AreaPopwindow showPop(){
        IssueDemandActivity mContext = (IssueDemandActivity) this.mContext;
        customPopWindow = new CustomPopWindow.PopupWindowBuilder(this.mContext).setView(popView)
                .size(ViewGroup.LayoutParams.MATCH_PARENT, 400)
                .setFocusable(true)
                .setOnDissmissListener(new PopupWindow.OnDismissListener() {
                    @Override
                    public void onDismiss() {
                        mContext.showAreaName();
                    }
                })
                .setOutsideTouchable(false)
                .enableBackgroundDark(true)
                .create()//创建PopupWindow
                .showAtLocation(view, Gravity.BOTTOM, 0, 0);
        return this;
    }

    public void disMiss() {
        if (null != customPopWindow) {
            customPopWindow.dissmiss();
        }
    }
    public View getView(int viewId){
        return popView.findViewById(viewId);
    }
}
